function numberToChineseFull(number) {
  const chineseNumbers = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
  const unit = ["", "十", "百", "千"];
  const unit2 = ["", "万", "亿", "兆"];

  if (number === 0) {
    return chineseNumbers[0];
  }

  let result = "";
  let numStr = String(number);
  let numLength = numStr.length;

  for (let i = 0; i < numLength; i++) {
    const digit = Number(numStr[i]);
    const unitIndex = numLength - i - 1;

    if (digit !== 0) {
      if (result.endsWith("零") && digit !== 1) {
        result = result.slice(0, -1);
      }
      
      if (digit === 1 && unitIndex > 0) {
        result += unit[unitIndex];
      } else {
        result += chineseNumbers[digit] + unit[unitIndex];
      }
    } else if (digit === 0 && !result.endsWith("零")) {
      // result += "零";
    }

    if (unitIndex === 0 && (numLength - i - 1) % 4 === 0 && numLength > 4) {
      result += unit2[Math.floor((numLength - i - 1) / 4)];
    }
  }

  return result;
}

module.exports = numberToChineseFull;
